package com.lsb.service;

import com.lsb.dao.DataDao;
import com.lsb.pojo.RegionStats;
import com.lsb.vo.ChartVO;
import com.lsb.vo.StateChartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * @author ：liusibo
 * @description：TODO
 * @date ：2021/5/3 13:33
 */
@Service
public class DataServiceImpl implements DataService{
    @Autowired
    private DataDao dataDao;

    @Override
    public List<RegionStats> getAllStats() {
        return dataDao.getStatsList();
    }

    @Override
    public List<RegionStats> getByCountryName(String countryName) {
        List<RegionStats> statsList = dataDao.getStatsList();
        List<RegionStats> resultList = new ArrayList<>();
        statsList.forEach(regionStats -> {
            if(regionStats.getCountry().toLowerCase().contains(countryName.toLowerCase())){
                resultList.add(regionStats);
            }
        });
        return resultList;
    }

    @Override
    public List<RegionStats> getByStateName(String stateName) {
        List<RegionStats> statsList = dataDao.getStatsList();
        List<RegionStats> resultList = new ArrayList<>();
        statsList.forEach(regionStats -> {
            if(regionStats.getState().toLowerCase().contains(stateName.toLowerCase())){
                resultList.add(regionStats);
            }
        });
        return resultList;
    }

    @Override
    public List<RegionStats> getById(Integer id) {
        List<RegionStats> statsList = dataDao.getStatsList();
        List<RegionStats> resultList = new ArrayList<>();
        statsList.forEach(regionStats -> {
            if(regionStats.getId().equals(id)){
                resultList.add(regionStats);
            }
        });
        return resultList;
    }

    @Override
    public List<ChartVO> getChartVO() {
        return dataDao.getChartVOList();
    }

    @Override
    public StateChartVO getStateChartVOById(Integer id) {
        List<StateChartVO> stateChartVOList = dataDao.getStateChartVOList();
        for (StateChartVO stateChartVO : stateChartVOList) {
            if(stateChartVO.getId().equals(id)){
                return stateChartVO;
            }
        }
        return null;
    }
}
